!function () {
    var menuList = [],
        menuList2=[],
        type;
    var init = function () {
        initEvent();
        getDate();
        renderMenu();
        getType();
        // getDate2();
    }
    var initEvent = function () {   
        $('.zyArr').on('click','li',OnAclick);
    
    }
    // var getDate2 = function () {
    //     $.ajax({
    //         url: "http://localhost/api.php/laizhou/type",
    //         type: "get",
    //         data: {
    //             transform: 1,
    //             order: "id",
    //             filter: 'level,eq,二级菜单'
    //         },
    //         success: function (res) {
    //             menuList2 = res.type;
    //             // console.log(menuList2);
            
    //         }
    //     })
    // }
    var getType=function(){
        type=decodeURIComponent(location.search.substr(6))  ;
        localStorage.setItem('fen',location.search);
    
      }
    var  OnAclick  =function(e){
        var i=e.currentTarget.dataset.p;
        // var $this=$(this);
        // console.log(1);
        localStorage.getItem('zylistDate');
        location.href='../home/detial2.html';
    }

    var delerji=function(yiji){
        var erjiArr = []
        menuList2.forEach(function(item){
            item.belong==yiji?erjiArr.push(item):null;
        })
        var lis = ''
        erjiArr.forEach(function(item){
            lis = lis + ('<li>'+item.name+'</li>')
        })
        console.log(lis);
        return lis
    }

    var delFenleierji=function(yiji){
        var erjiArr = []
        menuList2.forEach(function(item){
            item.belong==yiji?erjiArr.push(item):null;
        })
        var lis = ''
        erjiArr.forEach(function(item){
            lis = lis + ('<span><a>'+item.name+'</a></span>')
        })
        console.log(lis);
        return lis
    }


    var getDate = function () {
        $.ajax({
            url: "http://localhost/api.php/laizhou/type",
            type: "get",
            data: {
                transform: 1,
                order: "id",
                // filter: 'level,eq,一级菜单'
            },
            success: function (res) {
                var typeArr = res.type
                menuList = typeArr.filter(function(item){
                    return item.level == '一级菜单'
                })
                menuList2 = typeArr.filter(function(item){
                    return item.level == '二级菜单'
                })
                renderMenu();
                renderMenu2();
                renderFenlei();
                // renderfenlei2();
                // console.log(menuList);
            }
        })
    }

    var renderFenlei=function(){
       var $FLYijiArr=[];
       $.each(menuList, function (i, o) {
        $FLYijiArr.push('<div class="fabu_nr_bigsmall">',
        '<div class="fabu_bigbt">',o.name,'</div>',
        '<div class="fabu_smallbt">',
        delFenleierji(o.name),
        '</div>',
        '</div>')
    })
     $('.fabu-mess-content').html($FLYijiArr.join(''))
    }

    var renderMenu = function () {
        var $menuArr = [];
        $.each(menuList, function (i, o) {
            $menuArr.push('<li><a href="./detial.html?type=',o.name,'" target="_blank">', o.name, '</a></li>')

        })
        $('.nav-list').append($menuArr.join(''));
    }

    var renderMenu2 = function () {
        var $menuArr2 = [];
           
        $.each(menuList, function (i, o){
            $menuArr2.push('<a  style="color:#333;position:relative" a href="./detial.html?type=',o.name,'"><li  style="cursor:pointer;" class="yiji"><img src="http://www.laizhouba.com/newtemplate/images/fangwu_ico.jpg"><span>', o.name, '</span>',
                '<div class="erji">',
                '<ul>',
                delerji(o.name),
                '</ul>',
                '</div>',
                '</li>',
                '</a>')

        })
        $('#add-menu').html($menuArr2.join(''));  
    }
    init();

}()